//打印倒正金字塔  
function triangle() {
    let num = prompt('请输入层数：');
    if (isNaN(num) || num === '') {
        alert('请输入正确的数字');
        triangle();
    } else if (num % 2 === 0) {
        num--;
    }
    num = parseInt(num);
    let num1 = num / 2;
    //上层
    for (let i = 0; i < num1; i++) {
        for (let j = 0; j < i; j++) {
            document.write('<div></div>');
        }
        for (let k = 0; k <= 2 * (num1 - i) - 1; k++) {
            document.write('<div>——</div>');
        }

        document.write('<br/>');
    }
    //下层
    for (let m = 0; m < num1 - 1; m++) {
        for (let n = 0; n < num1 - 1 - m - 1; n++) {
            document.write('<div></div>');
        }
        for (let t = 1; t < 2 * m + 4; t++) {
            document.write('<div>——</div>');
        }
        document.write('<br/>');
    }

}
triangle()